import 'package:flutter/material.dart';
import 'package:flutter_food_ordering_web/res/colors.dart';
import 'package:flutter_food_ordering_web/res/dimens.dart';
import 'package:flutter_food_ordering_web/routers/fluro_navigator.dart';

class MyDialog extends Dialog {

  String title = '温馨提示';
  String content = '您好！！将为您结算餐车内美食。';
  String okText = '确定';
  String cancelText = '取消';
  //是否只显示一个确认按钮
  bool showOnlyOkBtn = false;
  Function(bool) onPressed;

  MyDialog({Key key,
    this.title,
    this.content,
    this.okText,
    this.cancelText,
    this.showOnlyOkBtn,
    this.onPressed}) : super(key: key);
  
  @override
  Widget build(BuildContext context) {
    return Material( //创建透明层
      // type: MaterialType.transparency, //透明类型
      color: Color(0x33eeefcb),
      child: new Center( //保证控件居中效果
        child: Container(
          width: 250,
          height: 120,
          child: Column(
            children: <Widget>[
              Container(
                height: 30,
                padding: const EdgeInsets.only(left: 13.5, right: 11),
                decoration: BoxDecoration(
                  color: Color(0xfff5f5f5),
                  borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(5),
                    topRight: Radius.circular(5),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text(title,
                      style: TextStyle(
                        fontSize: Dimens.font_sp10,
                        color: Colours.text_dark
                      ),
                    ),
                    InkWell(
                      onTap: () {
                        NavigatorUtils.goBack(context);
                      },
                      child: Icon(Icons.close,
                        color: Color(0xffd8d8d8),
                        size: 16,
                      )
                    )
                  ],
                ),
              ),
              Expanded(
                child: Container(
                  width: double.infinity,
                  color: Colors.white,
                  padding: const EdgeInsets.only(left: 13.5, right: 13.5, top: 15, bottom: 16.5),
                  child: Text(content,
                    style: TextStyle(
                      fontSize: Dimens.font_sp10,
                      color: Colours.text_dark
                    ),
                  ),
                ),
              ),
              Container(
                padding: const EdgeInsets.only(left: 30, right: 30, bottom: 18),
                decoration: BoxDecoration(
                  color: Colors.white,
                  border: Border.fromBorderSide(BorderSide(color: Colors.white)),
                  borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(5),
                    bottomRight: Radius.circular(5),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    _buildOkButton(context),
                    _buildCancelButton(context)
                  ],
                ),
              )
            ]
          ),
        )
      )
    );
  }

  //左边确认按钮
  Widget _buildOkButton(BuildContext context) {
    return InkWell(
      onTap: () {
        NavigatorUtils.goBack(context);
        onPressed(true);
      },
      child: Container(
        width: 82.5,
        height: 24,
        decoration: BoxDecoration(
          color: Color(0xffffad5d),
          border: Border.fromBorderSide(BorderSide(color: Color(0xffffad5d), width: 1)),
          borderRadius: BorderRadius.circular(2)
        ),
        child: Center(
          child: Text(okText,
            style: TextStyle(
              fontSize: Dimens.font_sp10,
              color: Colors.white
            ),
          ),
        )
      ),
    );
  }

  //右边取消按钮
  Widget _buildCancelButton(BuildContext context) {
    return InkWell(
      onTap: () {
        NavigatorUtils.goBack(context);
        onPressed(false);
      },
      child: Container(
        width: 82.5,
        height: 24,
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border.fromBorderSide(BorderSide(color: Color(0xffffad5d), width: 1)),
          borderRadius: BorderRadius.circular(2)
        ),
        child: Center(
          child: Text(cancelText,
            style: TextStyle(
              fontSize: Dimens.font_sp10,
              color: Color(0xffffad5d)
            ),
          ),
        )
      ),
    );
  }
}